import java.awt.*;
import java.awt.image.BufferedImage;
import java.awt.event.*;
import java.io.*;
import java.net.*;
import java.nio.channels.ClosedByInterruptException;
import java.util.ArrayList;
import java.util.List;

import javax.imageio.ImageIO;
import javax.swing.*;
import javax.swing.event.*;

import java.awt.geom.AffineTransform;
import java.util.Random;

class BetButton extends JButton
{
	private int status, mode;// bet/rise/all-in -- mode : 0 bet 1=raise 2=allin only
	private String [] buttonLabels;
	private boolean canCall;
	public BetButton(int stat)
	{
		super("Call");
		canCall = true;
		buttonLabels = new String[4];
		buttonLabels[0] = new String("Call");
		buttonLabels[1] = new String("Bet");
		buttonLabels[2] = new String("Rise");
		buttonLabels[3] = new String("All-in");
		status = stat;
		mode = 0;
		setText(buttonLabels[status]);
	}
	public int getStatus()
	{
		return status;
	}
	public String getStrStatus()
	{
		return buttonLabels[status];
	}
	public void setStatus(int stat)
	{
		status = stat;
		if (mode == 2 || status == 2)
		{
			setText(buttonLabels[3]);
			return;
		}
		if (status==0 && canCall==true) setText(buttonLabels[status]);
		if (canCall==false) status=1;
		if (status==1)
		{
			if (mode==0) setText(buttonLabels[1]); else setText(buttonLabels[2]);
		}
	}
	public String checkStringStatus()
	{
		return getText();
	}
	public void setMode(int m)
	{
		mode = m;
	}
	public int getMode()
	{
		return mode;
	}
	public void setCall(boolean b)
	{
		canCall = b;
	}
	public boolean call()
	{
		return canCall;
	}
}



class ClientPlayer
{
	public int chips, bet, status, onServerId, tablePos;
	public static String [] statusDescription = { "" ,"Bet", "Raised", "All-in", "Folded", "Checked", "Call"};
	public String nick;
	public boolean dealer, smallBlind, bigBlind;
	public Card [] playerCards = new Card [4];
	boolean showCards;
	boolean player;
	public ClientPlayer playerOnLeft;
	public ClientPlayer(String nick, int i)
	{
		this.nick = nick;
		showCards = false;
		onServerId = i;
	}
}

public class MainWindow extends JFrame implements ActionListener {
	
	//variables
	private Socket socket = null;
	private PrintWriter out = null;
	private BufferedReader in = null;
	int windowWidth = 610;
	int windowHeight = 610;
	int diff = 150;
	private List<ClientPlayer> clientPlayers;
	private int pot;
	private int mode;
	private int turn, round;
	
	//components
	private BetButton betButton;
	private JButton checkButton;
	private JButton foldButton;
	private JButton change;
	private JSlider slider;
	private GraphicPanel gamePanel;
	private JPanel buttonPanel;
	private JPanel split2;
	private JPanel split1;
	private JTextArea communicator;
	private JScrollPane communicatorScroll;
	private Canvas canvas;
	private JLabel betLabel;
	private JCheckBox [] cards_to_change;
	
	
	private int maxBet()
	{
		int max = 0;
		for (int i=1; i<clientPlayers.size(); i++)
		{
			if (clientPlayers.get(i).chips>max) max = clientPlayers.get(i).chips;
		}
		return max;
	}
	private void enableAuction(boolean b)
	{
		betButton.setEnabled(b);
		checkButton.setEnabled(b);
		foldButton.setEnabled(b);
		slider.setEnabled(b);
		betLabel.setEnabled(b);
	}
	private void enableChange(boolean b)
	{
		change.setEnabled(b);
		for (int i=0; i<4; i++)
		{
			cards_to_change[i].setEnabled(b);
			cards_to_change[i].setSelected(false);
		}
	}
	private void auctionRemove()
	{
		split1.remove(betButton);
		split1.remove(checkButton);
		split1.remove(foldButton);
		split1.remove(slider);
		split1.remove(betLabel);
	}
	private void auctionAdd()
	{
		split1.add(slider);
		split1.add(betLabel);
		split1.add(betButton);
		split1.add(checkButton);
		split1.add(foldButton);
	}
	private void changeRemove()
	{
		split1.remove(cards_to_change[0]);
		split1.remove(cards_to_change[1]);
		split1.remove(cards_to_change[2]);
		split1.remove(cards_to_change[3]);
		split1.remove(change);
	}
	private void changeAdd()
	{
		split1.add(cards_to_change[0]);
		split1.add(cards_to_change[1]);
		split1.add(cards_to_change[2]);
		split1.add(cards_to_change[3]);
		split1.add(change);
	}
	private void setAuctionVisible(boolean b)
	{
		slider.setVisible(b);
		betLabel.setVisible(b);
		betButton.setVisible(b);
		checkButton.setVisible(b);
		foldButton.setVisible(b);
	}
	private void setChangeVisible(boolean b)
	{
		for (int i=0; i<4; i++)
		{
			cards_to_change[i].setVisible(b);
		}
		change.setVisible(b);
	}
	private void append(String s)
	{
		communicator.append(s);
		JScrollBar vertical = communicatorScroll.getVerticalScrollBar();
		vertical.setValue( vertical.getMaximum() );
	}
	/*public void deleteClientPlayer(int i)
	{
		clientPlayers.remove(i);
	}*/
	
	public MainWindow(Socket socke, PrintWriter ou, BufferedReader inn, String nick)
	{
		//variables
		super("Badugi - " + nick);
	
		socket = socke;
		out = ou;
		in = inn;
		betButton = new BetButton(0);
		checkButton = new JButton("Check");
		foldButton = new JButton("Fold");
		slider = new JSlider();
		gamePanel = new GraphicPanel(true);
		buttonPanel = new JPanel();
		split1 = new JPanel(true);
		split2 = new JPanel();
		communicator = new JTextArea();
		betLabel = new JLabel();
		cards_to_change = new JCheckBox [4];
		change = new JButton("Change");
		for (int i=0; i<4; i++)
		{
			cards_to_change[i] = new JCheckBox(i+"");
		}
		
		communicatorScroll = new JScrollPane ( communicator );
		communicatorScroll.setVerticalScrollBarPolicy ( ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS );

		
		BorderLayout layout = new BorderLayout();
		setBounds(111,50,windowWidth,windowHeight);
		setMinimumSize(new Dimension(windowWidth, windowHeight));
		//gamePanel.setSize(windowWidth,windowHeight-diff);
		//buttonPanel.setSize(windowWidth,diff);
		//setLayout(new GridLayout(2,1));
		
		//buttonPanel.setBackground(new Color(50,100,230));
		split1.setLayout(new FlowLayout());
		
		buttonPanel.setLayout(new GridLayout(2,1));
		
		
		slider.setPreferredSize(new Dimension(windowWidth/2,diff/2));
		buttonPanel.setPreferredSize(new Dimension(windowWidth, diff));
		communicator.setEditable(false);
		//communicator.setPreferredSize(new Dimension(windowWidth-5, (diff/2)-5));
		communicatorScroll.setPreferredSize(new Dimension(windowWidth-20, (diff/2)-10));
		betLabel.setText(Integer.toString(slider.getValue()));
		

		slider.setValue(0);
		split1.add(slider);
		split1.add(betLabel);
		split1.add(betButton);
		split1.add(checkButton);
		split1.add(foldButton);
		split2.add(communicatorScroll);
		for (int i=0; i<4; i++)
		{
			split1.add(cards_to_change[i]);
		}
		split1.add(change);
		
		buttonPanel.add(split1);
		buttonPanel.add(split2);
		gamePanel.loadGraphic();
		gamePanel.setPreferredSize(new Dimension(windowWidth, windowHeight - diff -1));
		add(gamePanel, BorderLayout.CENTER);
		
		add(buttonPanel, BorderLayout.SOUTH);
		//gamePanel.repaint();
		slider.setPaintLabels(true);
		
		clientPlayers = new ArrayList<ClientPlayer>();
		clientPlayers.add(new ClientPlayer(nick, 0));
		//communicator.append("<html><center><b>Badugi game console</b></center></html>\n");
		round = 1;
		
		//setResizable(false);
		setVisible(true);
		//split1.setVisible(false);
		enableAuction(false);
		ClientThread thread = new ClientThread();
		thread.start();
		try {Thread.sleep(1000);} catch(InterruptedException e){}
		
		//LISTENERS
		betButton.addActionListener(this);
		checkButton.addActionListener(this);
		foldButton.addActionListener(this);
		change.addActionListener(this);
		slider.addChangeListener(new ChangeListener() {
            @Override
            public void stateChanged(ChangeEvent e) {
            	betLabel.setText(Integer.toString(slider.getValue()));
            	if (slider.getValue()==slider.getMinimum())
            	{
            		if (betButton.call() == true)
            		{
            			betButton.setStatus(0);
            		}
            		else
            		{
            			betButton.setStatus(1);
            		}
            	}
            	if (slider.getValue()==slider.getMaximum())
            	{
            		betButton.setStatus(2);
            	}
            	if ((slider.getValue() > slider.getMinimum()) && (slider.getValue() < slider.getMaximum()))
            	{
            		betButton.setStatus(1);
            	}
            	split1.repaint();
            }
		});
		addWindowListener( new WindowAdapter() {
            public void windowClosing(WindowEvent e) {
			     out.println("Q");
			     System.out.println("sent Q");
			     System.exit(0);
			     try
				 {
			    	 System.out.println("Closing sockets and IO");
			    	 out.close();
					 in.close();
					 socket.close();
				 }
			     catch(IOException ex)
			     {
			    	 System.out.println("error in closing socket and I/O");
			     }
			     System.out.println("Exiting");
            	System.exit(0);
            }
			   });
	}
	//************************
	//ACTION LISTENER FOR BUTTONS
	public void actionPerformed(ActionEvent event)
	{
		String strOut = new String();
		if(event.getSource() == betButton)
		{
			strOut = new String();
			strOut = "R";
			System.out.println("in betbutton listener");
			if (betButton.getStatus()==0)
			{
				System.out.println("clicked call");
				strOut += " C";
			}
			if (betButton.getStatus() == 1 && betButton.getMode()==0)
			{
				System.out.println("clicked bet");
				strOut += " B " + slider.getValue();
			}
			if (betButton.getStatus() == 1 && betButton.getMode()!=0)
			{
				System.out.println("clicked raise");
				strOut += " R " + slider.getValue();
			}
			if (betButton.getStatus() == 2 || betButton.getMode()==2)
			{
				System.out.println("clicked allin");
				strOut += " A";
			}
			enableAuction(false);
			enableChange(false);
			System.out.println("Out: " + strOut);
			out.println(strOut);
		}
		if(event.getSource() == foldButton)
		{
			strOut = "R F";
			enableAuction(false);
			enableChange(false);
			System.out.println("Out: " + strOut);
			out.println(strOut);
		}
		if(event.getSource() == checkButton)
		{
			strOut = "R H";
			enableAuction(false);
			enableChange(false);
			System.out.println("Out: " + strOut);
			out.println(strOut);
		}
		if(event.getSource() == change)
		{
			strOut = "C";
			for (int i=0; i<4; i++)
			{
				if (cards_to_change[i].isSelected() == true)
				{
					strOut += " "+ i;
				}
			}
			System.out.println("change Out: " + strOut);
			out.println(strOut);
			System.out.println("switching to action");
			/*changeRemove();
			auctionAdd();*/
			setChangeVisible(false);
			setAuctionVisible(true);
			enableChange(false);
			enableAuction(false);
			split1.repaint();
			
		}
	}
	
	class ClientThread extends Thread
	{
		ClientThread()
		{
			super();
		}
		//private void
		public synchronized void run()
		{
			//gettin initial client information
			String line = new String();

			//initial data catching (nicks, etc)
			while (true)
			{
				yield();
				try
				{
					line = in.readLine();
				}
				catch (IOException e)
				{
					System.out.println(e);
					System.exit(0);
				}
				String [] ss = line.split(" ");
				System.out.println(line);
				if (line.equals("end") == true) break;
				int i = Integer.parseInt(ss[1]);
				clientPlayers.add(new ClientPlayer(ss[0], i));
				
			}
			//getting your own id
			try
			{
				line = in.readLine();
			}
			catch (IOException e)
			{
				System.out.println(e);
				System.exit(0);
			}
			int a = Integer.parseInt(line);
			clientPlayers.get(0).onServerId = a;
			//********************************
			
			
			ServerListenThread listenThread = new ServerListenThread();
			listenThread.start();
			try
			{
				sleep(1000);
			}
			catch (InterruptedException e){}
			for (int i=0 ; i<clientPlayers.size()-1; i++)
			{
				clientPlayers.get(i).playerOnLeft = clientPlayers.get(i+1);
			}
			clientPlayers.get(clientPlayers.size()-1).playerOnLeft =  clientPlayers.get(0);
			for (int i =0; i<clientPlayers.size(); i++)
			{
				clientPlayers.get(i).tablePos = i;
			}
			/*slider.setMinimum(0);
			slider.setMaximum(clientPlayers.get(0).chips);
			slider.setLabelTable(slider.createStandardLabels(slider.getMaximum()));*/
			//main game loop
			while (true)
			{
				yield();
				turn=0; mode=0;
				//reading start round data
			
				
				
				
				/*for (int i=0; i<clientPlayers.size(); i++)
				{
					clientPlayers.get(i).showCards = false;
				}*/
				while (true)
				{
					Thread.yield();
					
				}
				
			}
			
		}
	}
	//thread listening to server communicats
	class ServerListenThread extends Thread
	{
		private ClientPlayer player;
		public ServerListenThread()
		{
			player = clientPlayers.get(0);
		}
		public synchronized void run()
		{
			while (true)
			{
				yield();
				System.out.println("jestem w listen");
				String threadLine = new String();
				try
				{
					threadLine = in.readLine();
				}
				catch (IOException e)
				{
					System.out.println(e);
					System.exit(0);
				}
				System.out.println("Read: " + threadLine);
				if (threadLine==null) continue;
				String [] threadSplitStr = threadLine.split(" ");
				//********
				//Quit
				//********
				if (threadSplitStr[0].equals("Q"))
				{
					int playerToRemove = 0;
					playerToRemove = Integer.parseInt(threadSplitStr[1]);
					/*if (clientPlayers.get(0).onServerId == playerToRemove)
					{
						JOptionPane.showMessageDialog(null, "Game over");
						System.exit(0);
					}*/
					System.out.println("Deleting player with id " + playerToRemove);
			
					for (int i=0; i<clientPlayers.size(); i++)
					{
						if (clientPlayers.get(i).onServerId==playerToRemove) 
						{
							System.out.println("Player " + clientPlayers.get(i).nick + " " + 
							clientPlayers.get(i).onServerId + " disconnected");
							//searching players on right
							for (int j=0 ; j<clientPlayers.size(); j++)
							{
								if (clientPlayers.get(j).playerOnLeft == clientPlayers.get(i))
								{
									clientPlayers.get(j).playerOnLeft = clientPlayers.get(i).playerOnLeft;
									//break;
								}
							}
							clientPlayers.remove(i);
						}
						gamePanel.repaint();
					}
					System.out.println("Players left: ");
					for (int i=0; i<clientPlayers.size(); i++)
					{
						System.out.println(clientPlayers.get(i).nick);
					}
				}
				//*******
				//sending info
				//*********
				if (threadLine.equals("D"))
				{
					//System.out.println("getting info about all players form server");
					int counter = 0;
                    while (true)
                    {
                            try
                            {
                                    threadLine = in.readLine();
                            }
                            catch (IOException e)
                            {
                                    System.out.println(e);
                                    System.exit(0);
                            }
                            //System.out.println("Line: " + threadLine + " counter: " + counter);
                            if (threadLine.equals("end") == true) break;
                            String [] splitStr = threadLine.split(" ");
                            //try
                            //{
                                    clientPlayers.get(counter).chips = Integer.parseInt(splitStr[0]);
                                    clientPlayers.get(counter).dealer = Boolean.parseBoolean(splitStr[1]);
                                    clientPlayers.get(counter).smallBlind = Boolean.parseBoolean(splitStr[2]);
                                    clientPlayers.get(counter).bigBlind = Boolean.parseBoolean(splitStr[3]);
                                    clientPlayers.get(counter).bet = Integer.parseInt(splitStr[8]);
                                    pot = Integer.parseInt(splitStr[9]);
                                    clientPlayers.get(counter).status = Integer.parseInt(splitStr[10]);
                                    round = Integer.parseInt(splitStr[11]);
                                    if (Integer.parseInt(splitStr[12]) == 1) clientPlayers.get(counter).showCards=true; else
                                    	clientPlayers.get(counter).showCards=false;
                                    //if (counter == 0)
                                    //{
                                            for (int i=0; i<4; i++)
                                            {
                                                    clientPlayers.get(counter).playerCards[i] = new Card(Integer.parseInt(splitStr[i+4]));
                   
                                            }
                                            //System.out.print("Get seq from server: ");
                                            //for (int i=0; i<splitStr.length; i++) System.out.println(splitStr[i]);
                                            //System.out.println(round + "round");
                                    //}
                            //}
                                    counter++;
                                    
                           gamePanel.letPaint();
                           gamePanel.repaint();
                    }
                    
                    for (int i=0; i<clientPlayers.size(); i++)
                    {
                    	ClientPlayer pl = clientPlayers.get(i);
                    	//System.out.println(pl.nick + " id-" +pl.onServerId);
                    }
                   
                    gamePanel.letPaint();
					
				}
				//************
				// Turn
				//************
				if (threadSplitStr[0].equals("T"))
				{
					if (mode == 12)
					{
						enableChange(false);
						enableAuction(false);
						auctionRemove();
					}
					else
					{
						if (threadSplitStr.length<=2)
						{
							if (threadSplitStr[1].equals("1"))
							{
								/*auctionRemove();
								changeAdd();
								enableChange(true);
								enableAuction(false);*/	
							}
						}
						else
						{
							//for moe 0 - auction
							
							
							turn = 1;
							/*changeRemove();
							auctionAdd();*/
							enableChange(false);
							enableAuction(true);
							setChangeVisible(false);
							setAuctionVisible(true);
							int sl = Integer.parseInt(threadSplitStr[1]);//slider
							int ch = Integer.parseInt(threadSplitStr[2]);//check
							int mod = Integer.parseInt(threadSplitStr[3]);//mode
							int big = Integer.parseInt(threadSplitStr[4]);//biggestbet
							betButton.setCall(true);
							if (sl == 0)
							{
								slider.setEnabled(false);
							}
							else
							{
								slider.setMinimum(big - clientPlayers.get(0).bet);
								
								System.out.println("slider min: " + big + " " + clientPlayers.get(0).bet);
								slider.setMaximum(clientPlayers.get(0).chips);
								slider.setLabelTable(slider.createStandardLabels(slider.getMaximum()-slider.getMinimum()));
								slider.setValue(slider.getMinimum());
								if (ch != 0 && clientPlayers.get(0).chips!=0) 
								{
									slider.setMinimum(slider.getMinimum()+1);
									slider.setLabelTable(slider.createStandardLabels(slider.getMaximum()-slider.getMinimum()));
									betButton.setCall(false);
									betButton.setStatus(1);
								}
							}
							if (ch == 0)
							{
								checkButton.setEnabled(false);
							}
							betButton.setMode(mod);
							split1.repaint();
							split1.revalidate();
						}
					}	
				}
				//************
				// Mode
				//************
				if (threadSplitStr[0].equals("M"))
				{
					int a = Integer.parseInt(threadSplitStr[1]);
					/*mode = a;
					if (a==0)
					{
						System.out.println("Mode 0");
						changeRemove();
						auctionAdd();
						enableAuction(false);
						enableChange(false);
						
					}
					if (a==1)
					{
						System.out.println("Mode 1");
						auctionRemove();
						changeAdd();
						enableAuction(false);
						enableChange(false);
					}
					*/
					
				}
				if (threadLine.equals("CH"))
				{
					System.out.println("switching to chagne");
					enableChange(true);
					enableAuction(false);
					setAuctionVisible(false);
					setChangeVisible(true);
					
				}
					
					
			}
		}
	}

	
	//**************************
	//**************************
	// GRAPHIC
	//**************************
	//**************************
	class GraphicPanel extends JPanel
	{
		Image [] cardImage;
		BufferedImage dealerImage;
		BufferedImage smallBlindImage;
		BufferedImage bigBlindImage;
		int [] Xpositions;
		int [] Ypositions;
		private boolean paintedFirst;
		public void letPaint()
		{
			paintedFirst = true;
		}
		
		public GraphicPanel()
		{
			super();
			paintedFirst=false;
		}
		public GraphicPanel(boolean bool)
		{
			super(bool);
			paintedFirst=false;
		}
		public void drawCenteredString(String s, int w, int h, Graphics g) {
		    FontMetrics fm = g.getFontMetrics();
		    int x = (w - fm.stringWidth(s)) / 2;
		    int y = (fm.getAscent() + (h - (fm.getAscent() + fm.getDescent())) / 2);
		    g.drawString(s, x, y);
		}
		public void loadGraphic()
		{
			cardImage = new Image[53+53];
			//Reading  images
			//s,h,d,c
			try 
			{
			    //img = ImageIO.read(new File("/cards/c01.bmp"));
			    cardImage[0] = ImageIO.read(getClass().getResourceAsStream("/cards/b1fv.jpg"));
			    cardImage[53] = ImageIO.read(getClass().getResourceAsStream("/cards/b1fh.jpg"));
			    System.out.println("Getting image from: /cards/b1fv.jpg");
			} 
			catch (IOException e) 
			{
				JOptionPane.showMessageDialog(null, "Couldn't load Imaage from File!!!");
			}
			for (int i=1; i<=4; i++)
			{
				for (int j=1; j<=13; j++)
				{
					String path = "/cards/";
					String path2 = "/cards/";
					switch(i)
					{
					case 1:
						path+= "s";
						path2+= "s";
						break;
					case 2:
						path+= "h";
						path2+= "h";
						break;
					case 3:
						path+= "d";
						path2+= "d";
						break;
					case 4:
						path+= "c";
						path2+= "c";
						break;
					}
					path += j;
					path += ".jpg";
					path2 += j;
					path2 += "h.jpg";
					try 
					{
						System.out.println("Getting image from: " + path);
					    cardImage[((i-1)*13)+j] = ImageIO.read(getClass().getResourceAsStream(path));
					    cardImage[53+((i-1)*13)+j] = ImageIO.read(getClass().getResourceAsStream(path2));
					} 
					catch (IOException e) 
					{
						JOptionPane.showMessageDialog(null, "Couldn't load Image from File!!!");
					}
				}
			}
			//loading buttons
			//*************************
			try 
			{
			    dealerImage = ImageIO.read(getClass().getResourceAsStream("/cards/dealer.png"));
			    smallBlindImage = ImageIO.read(getClass().getResourceAsStream("/cards/smallblind.png"));
			    bigBlindImage = ImageIO.read(getClass().getResourceAsStream("/cards/bigblind.png"));
			} 
			catch (IOException e) 
			{
				JOptionPane.showMessageDialog(null, "Couldn't load Imaage from File!!!");
			}
			
		}
		public void paintComponent(Graphics g) 
		{
			if (paintedFirst == false)
			{
				/*try
				{
					Thread.sleep(1000);
				}
				catch (InterruptedException e)
				{
					System.out.println(e);
				}
				paintedFirst=true;*/
				return;
			}
		    int width = getWidth();
		    int height = getHeight();
		    g.setColor(new Color(100,225,71));
		    g.fillRect(0, 0, width, height);
		    g.setColor(new Color(170,250,140));
		    g.fillOval((width/2)-70, (height/2)-40, 140, 80);
		    g.setFont(new Font("TimesRoman", Font.PLAIN, 12));
		    
		    //drawing all players
		    
		    for (int i=0 ; i<clientPlayers.size(); i++)
		    {
		    	int pos = clientPlayers.get(i).tablePos;
		    	ClientPlayer player_tmp = clientPlayers.get(i);
		    	//variables helping to draw
		    	int vcw = cardImage[0].getWidth(null); //vertical card width
		    	int vch = cardImage[0].getHeight(null);
		    	int hcw = cardImage[53].getWidth(null);
		    	int hch = cardImage[53].getHeight(null);
		    	int border = 10; //distance from screen line
		    	int dist = 50;
		    	//int id = clientPlayers.get(i).onServerId;
		    	g.setColor(new Color(20,20,20));
		    	/*for (int x=0; x<clientPlayers.size(); x++)
				{
					clientPlayers.get(x).showCards = true;
		    		
				}*/
		    	if (pos==0)
		    	{
		    		//drawing cards
		    		ClientPlayer pl = player_tmp;
		    		if (clientPlayers.get(0).status!=4)
		    		{
			    		for (int j=0; j<4; j++)
			    		{
			    			if (pos==0 || pl.showCards == true)
			    			{
			    				g.drawImage(cardImage[pl.playerCards[j].getId()], width-(4*vcw)+(j*vcw)-dist, 
			    						height-vch-border, null);
			    			}
			    			else
			    			{
			    				g.drawImage(cardImage[0], width-(4*vcw)+(j*vcw)-dist, 
			    						height-vch-border, null);
			    			}
			    		}
		    		}
		    		g.drawString(pl.nick + " - " + pl.chips, width-4*vcw-dist, height-vch-30 );
		    		g.drawString("Bet: " + pl.bet, width-4*vcw-dist, height-vch-15 );
		    		g.drawString(ClientPlayer.statusDescription[pl.status], width-4*vcw-dist + 100, height-vch-15 );
		    		if (pl.dealer == true) g.drawImage(dealerImage, width-4*vcw-dist+100, height-vch-dist+5, null);
		    		if (pl.bigBlind == true) g.drawImage(bigBlindImage, width-4*vcw-dist+22+100, height-vch-dist+5, null);
		    		if (pl.smallBlind == true) g.drawImage(smallBlindImage, width-4*vcw-dist+22+100, height-vch-dist+5, null);
		    	}
		    	if (pos==1)
		    	{
		    		//drawing cards
		    		ClientPlayer pl = player_tmp;
		    		if (pl.status!=4)
		    		{
			    		for (int j=0; j<4; j++)
			    		{
			    			if (pl.showCards == true)
			    			{
			    				System.out.println("jestem w true i proboje wydrukowac karte "+ pl.playerCards[j].getId());
			    				g.drawImage(cardImage[pl.playerCards[j].getId()], (j*vcw)+dist, 
			    						height-vch-border, null);
			    			}
			    			else
			    			{
			    				g.drawImage(cardImage[0], (j*vcw)+dist, 
			    						height-vch-border, null);
			    			}
			    		}
		    		}
		    		g.drawString(pl.nick + " - " + pl.chips, dist, height-vch-30 );
		    		g.drawString("Bet: " + pl.bet, dist, height-vch-15 );
		    		g.drawString(ClientPlayer.statusDescription[pl.status], dist + 100, height-vch-15 );
		    		if (pl.dealer == true) g.drawImage(dealerImage, dist+100, height-vch-dist+5, null);
		    		if (pl.bigBlind == true) g.drawImage(bigBlindImage, dist+22+100, height-vch-dist+5, null);
		    		if (pl.smallBlind == true) g.drawImage(smallBlindImage, dist+22+100, height-vch-dist+5, null);
		    	}
		    	if (pos==2)
		    	{
		    		//drawing cards
		    		ClientPlayer pl = player_tmp;
		    		if (pl.status!=4)
		    		{
			    		for (int j=0; j<4; j++)
			    		{
			    			if ( pl.showCards == true)
			    			{
			    				g.drawImage(cardImage[pl.playerCards[j].getId()+53], border, (height/2)-2*hch+j*hch, null);
			    						
			    			}
			    			else
			    			{
			    				g.drawImage(cardImage[0+53], border, (height/2)-2*hch+j*hch, null);
			    			}
			    		}
		    		}
		    		g.drawString(pl.nick + " - " + pl.chips, hcw+3+border, (height/2)-20 );
		    		g.drawString("Bet: " + pl.bet, hcw+3+border, (height/2)-5 );
		    		g.drawString(ClientPlayer.statusDescription[pl.status], hcw+3+border, (height/2)+10 );
		    		if (pl.dealer == true) g.drawImage(dealerImage, hcw+3+border, (height/2)+17, null);
		    		if (pl.bigBlind == true) g.drawImage(bigBlindImage, hcw+3+22+border, (height/2)+17, null);
		    		if (pl.smallBlind == true) g.drawImage(smallBlindImage, hcw+3+22+border, (height/2)+17, null);
		    	}
		    	if (pos==3)
		    	{
		    		//drawing cards
		    		ClientPlayer pl = player_tmp;
		    		if (pl.status!=4)
		    		{
			    		for (int j=0; j<4; j++)
			    		{
			    			if (pl.showCards == true)
			    			{
			    				g.drawImage(cardImage[pl.playerCards[j].getId()], (j*vcw)+dist, border, null);
			    			}
			    			else
			    			{
			    				g.drawImage(cardImage[0], (j*vcw)+dist, border, null);
			    			}
			    		}
		    		}
		    		g.drawString(pl.nick + " - " + pl.chips, dist, vch+border+15 );
		    		g.drawString("Bet: " + pl.bet, dist, vch+border+30 );
		    		g.drawString(ClientPlayer.statusDescription[pl.status], dist + 100, vch+border+15 );
		    		if (pl.dealer == true) g.drawImage(dealerImage, dist+100, vch+border+19, null);
		    		if (pl.bigBlind == true) g.drawImage(bigBlindImage, dist+22+100, vch+border+19, null);
		    		if (pl.smallBlind == true) g.drawImage(smallBlindImage, dist+22+100, vch+border+19, null);
		    	}
		    	if (pos==4)
		    	{
		    		//drawing cards
		    		ClientPlayer pl = player_tmp;
		    		if (pl.status!=4)
		    		{
			    		for (int j=0; j<4; j++)
			    		{
			    			if (pl.showCards == true)
			    			{
			    				g.drawImage(cardImage[pl.playerCards[j].getId()], width-(4*vcw)+(j*vcw)-dist, 
			    						border, null);
			    			}
			    			else
			    			{
			    				g.drawImage(cardImage[0], width-(4*vcw)+(j*vcw)-dist, 
			    						border, null);
			    			}
			    		}
		    		}
		    		g.drawString(pl.nick + " - " + pl.chips, width-4*vcw-dist, vch+border+15 );
		    		g.drawString("Bet: " + pl.bet, width-4*vcw-dist, vch+border+30 );
		    		g.drawString(ClientPlayer.statusDescription[pl.status], width-4*vcw-dist + 100, vch+border+15 );
		    		if (pl.dealer == true) g.drawImage(dealerImage, width-4*vcw-dist+100, vch+border+19, null);
		    		if (pl.bigBlind == true) g.drawImage(bigBlindImage, width-4*vcw-dist+22+100, vch+border+19, null);
		    		if (pl.smallBlind == true) g.drawImage(smallBlindImage, width-4*vcw-dist+22+100, vch+border+19, null);
		    	}
		    	if (pos==5)
		    	{
		    		//drawing cards
		    		ClientPlayer pl = player_tmp;
		    		if (pl.status!=4)
		    		{
			    		for (int j=0; j<4; j++)
			    		{
			    			if (pl.showCards == true)
			    			{
			    				g.drawImage(cardImage[pl.playerCards[j].getId()+53], width-hcw-border, (height/2)-2*hch+j*hch, null);
			    						
			    			}
			    			else
			    			{
			    				g.drawImage(cardImage[0+53], width-hcw-border, (height/2)-2*hch+j*hch, null);
			    			}
			    		}
		    		}
		    		g.drawString(pl.nick, width-hcw-border-35-(pl.nick.length()*2), (height/2)-35 );
		    		g.drawString(pl.chips+"", width-hcw-border-45, (height/2)-20 );
		    		g.drawString("Bet: " + pl.bet, width-hcw-border-45, (height/2)-5 );
		    		g.drawString(ClientPlayer.statusDescription[pl.status], width-hcw-border-45, (height/2)+10 );
		    		if (pl.dealer == true) g.drawImage(dealerImage, width-hcw-border-45, (height/2)+17, null);
		    		if (pl.bigBlind == true) g.drawImage(bigBlindImage, width-hcw-border-22, (height/2)+17, null);
		    		if (pl.smallBlind == true) g.drawImage(smallBlindImage, width-hcw-border-22, (height/2)+17, null);
		    	}
		    	
		    	
		    }
		    g.setColor(new Color(140,100,60));
		    g.setFont(new Font("TimesRoman", Font.BOLD, 20));
		    drawCenteredString(pot+"", (width),(height),g);
		    g.setColor(new Color(100,100,100));
		    g.setFont(new Font("TimesRoman", Font.BOLD, 12));
		    drawCenteredString("Round " + round, (width),(height)+30,g);
		    
		    
		}
	}

}
